home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5853 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: in2.uu.net!telepath!usenet
  2. From: jdavis@inthenet.com (Papillon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: division problem
  5. Date: Wed, 21 Feb 1996 15:36:23 GMT
  6. Organization: inthenet.com
  7. Message-ID: <4gfdut$8n5@zoom2.telepath.com>
  8. References: <31097D77.11AA@rain.org> <4eirpq$8ut@airdmhor.gen.nz>
  9. NNTP-Posting-Host: slip1.inthenet.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. gumboot@airdmhor.gen.nz (Simon Hosie) wrote:
  13.  
  14. >tpaul:
  15. >> Can anyone show me why this does not work?  I am a beginner.
  16.  
  17. > 1> #include <stdio.h>
  18.  
  19. > 3> main ()
  20. > 4> {
  21. > 5>     int fahrenheit, celsius;
  22.  
  23. > 7>     printf("Fahrenheit temperature =?";
  24. > 8>     scanf("%d",fahrenheit);
  25. > 9>     celsius = 5/9*(fahrenheit-32);
  26. >10>     printf("Fahrenheit = %d, Celsius = %d", fahrenheit, celsius;
  27. >11> }
  28.  
  29. >  I don't know if the guy I told off answered this (I just looked at his
  30. >answer and got upset).  Firstly you don't have any closing brackets on your
  31. >printf()'s, secondly..
  32.  
  33. >  I can't quite remember how C chooses the types to use, I think it's the
  34. >first thing after the '='..  anyway, it's doing integer math.  The first
  35. >thing it does is divide 5 by 9, that gives 0 (the remainder is thrown away)
  36. >then it multiplies (fahrenheight - 32) by 0.
  37.  
  38. >  The solution is to do your multiplies first.  The solution is _not_ to use
  39. >floating point.
  40.  
  41. Also, the scanf() function should read:  scanf("%d", &fahrenheit) in
  42. order to read in the value and pass it.
  43.  
  44.